package utility

import (
	"math/rand"
	"time"
)


func GetRandomArr(maxNum, maxLen int) []int {
	rand.Seed(time.Now().UnixNano())
	arrLen := rand.Intn(maxLen)
	arr := make([]int, arrLen)
	for i:=0 ;i<arrLen; i++ {
		arr[i] = rand.Intn(maxNum)
	}
	return arr
}

func IsSorted(arr []int) bool {
	if len(arr) < 2 {return true}
	for i:=1; i<len(arr); i++ {
		if arr[i] < arr[i-1] {
			return false
		}
	}
	return true
}

func IsEqualed(arr1 []int, arr2 []int) bool {
	if arr1 == nil && arr2 == nil {return true}
	if len(arr1) != len(arr2) {return false}
	for i:=0; i<len(arr1); i++ {
		if arr1[i] != arr2[i] {
			return false
		}
	}
	return true
}

func DeepCopy(arr []int) []int {
	ans := make([]int, len(arr))
	for i:=0; i<len(arr); i++ {
		ans[i] = arr[i]
	}
	return ans
}

func GetRandomInt(max int) int {
	reMax :=  max * 2
	rand.Seed(time.Now().UnixNano())
	//time.Sleep(time.Nanosecond)
	return rand.Intn(reMax) - max
}

func Swap(arr []int, i, j int) {
	arr[i], arr[j] = arr[j], arr[i]
}